<?php
# file will contain functions to create home page

# main function to create main window for home page
function i_home(){


#####	create the dynamic table to display the meetings

	$html = ''; // variable to store html code for home page
	
	
	$html .= '<div class="wrapper">'.
				'<div class="header"></div>'.
				'<div class="mainPage">'.
					'<table width="615" height="276" border=" " style="margin-left:70px;">'.
						'<tr>'.
							'<td class="home_groups_cell" width="282">' .
								'<table width="265" border=" ">'.
									'<tr><td width="255"><div align="center"><b>List of groups</b></div></td></tr>';
	$grpArr = c_home_get_groups();
	$ci = sizeof($grpArr);
	for($i = 0; $i<$ci; $i++)
	{
		$grp = $grpArr[$i];
		$html .= 					'<tr><td><div align="center">' .

										'<a href=index.php?id='.I_GROUP_OVERVIEW.'&grp=' .$grp['id'] . '>' . $grp['name'] . '</a>' .

									'</div></td></tr>';
	}

	$html .=					'</table>'.
							'</td>'.
							'<td class="home_meetings_cell" width="249">'.
								'<table width="500" border=" ">'.
									'<tr><td colspan="5" align="center"><b>Nearest meetings</b></td></tr>'.
									'<tr>'.
										'<td><u>Date</u></td>'.
										'<td><div align="center"><u>Time</u></div></td>'.
										'<td><div align="center"><u>Duration</u></div></td>'.
										'<td><div align="center"><u>Group</u></div></td>'.
										'<td><div align="center"><u>Place</u></div></td>'.
									'</tr>';
	$meetArr = c_home_get_meetings();
	$ci = sizeof($meetArr);
	for($i = 0; $i<$ci; $i++)
	{
		$meet = $meetArr[$i];
		$html .= 					'<tr>'.
										'<td>'.$meet['date'].'</td>'.
										'<td><div align="center">'.$meet['time'].'</div></td>'.
										'<td><div align="center">'.$meet['duration'].'h</div></td>'.
										'<td><div align="center">'.$meet['group_name'].'</div></td>'.
										'<td><div align="center">'.$meet['place'].'</div></td>'.
									'</tr>';
	}
									// '<tr>'.
										// '<td>18.12.2012</td>'.
										// '<td><div align="center">12:00 - 14:00</div></td>'.
										// '<td><div align="center">Veni Vidi Vici</div></td>'.
										// '<td><div align="center">MSW</div></td>'.
									// '</tr>'.
									// '<tr>'.
										// '<td>19.12.2012</td>'.
										// '<td><div align="center">15:00 - 17:00</div></td>'.
										// '<td><div align="center">Veni Vidi Vici</div></td>'.
										// '<td><div align="center">HoF</div></td>'.
									// '</tr>'.
									// '<tr>'.
										// '<td>03.01.2013</td>'.
										// '<td><div align="center">07:00 - 14:00</div></td>'.
										// '<td><div align="center">Rift Keepers</div></td>'.
										// '<td><div align="center">MOW</div></td>'.
									// '</tr>'.
	$html .=					'</table>'.
							'</td>'.
						'</tr>'.
						'<tr>'.
							'<td><div align="right"><u>Timeline</u></div></td>'.
							'<td><div align="right">';
	$currDate = c_get_time_curr_date();
	$prevDate = c_get_time_prev_date($currDate);
	$prevHref = 'index.php?id='.I_HOME_PAGE.'&year='.$prevDate['year'].'&month='.$prevDate['month'].'&day='.$prevDate['day'];
	$nextDate = c_get_time_next_date($currDate);
	$nextHref = 'index.php?id='.I_HOME_PAGE.'&year='.$nextDate['year'].'&month='.$nextDate['month'].'&day='.$nextDate['day'];
	$html .=					'<a href="'.$prevHref.'">Prev</a>&nbsp;'.
								$currDate['year'].'/'.$currDate['month'].'/'.$currDate['day'].
								'&nbsp;<a href="'.$nextHref.'">Next</a>'.
							'</div></td>'.
						'</tr>'.

					'</table>'.
					'<table>'.
						'<tr>';
	$ci = 25;
	for($i=0;$i<$ci;$i++){
		$html .= 			'<td class="time_style">'.
								'<div class="time_number">'.$i.'</div>'.
							'</td>';
	}
	$html .=			'</tr>'.
						'<tr>';
	$timeArr = c_get_time_values($currDate); // get all free time for current date
	$ci = 25;
	for($i=0;$i<$ci;$i++){
		$style = 'time_style';
		if( in_array($i, $timeArr) ) $style .= ' time_black'; // if array value exist, color it
		$html .= 			'<td class="'.$style.'">'.
								'<p>&nbsp;</p>'.
							'</td>';
	}
	$html .=			'</tr>'.
					'</table>'.
				'</div>' .
			'</div>'.
			'<div class="clear">&nbsp;</div>';

	return $html;
	
} // i_home()
?>